<!-- saved from url=(0014)about:internet -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>unSubController.as</title>
<link rel="stylesheet" type="text/css" href="../../SourceStyles.css"/>
</head>

<body><pre><span class="ActionScriptComment">// ActionScript file
</span><span class="ActionScriptComment">/*
* 用户控制的接口
*/</span>

<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">mx</span>.<span class="ActionScriptDefault_Text">rpc</span>.<span class="ActionScriptDefault_Text">events</span>.<span class="ActionScriptDefault_Text">ResultEvent</span>;


<span class="ActionScriptComment">//触发退票流程事件
</span><span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">unSub</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
<span class="ActionScriptBracket/Brace">{</span>
    <span class="ActionScriptDefault_Text">FlightService</span>.<span class="ActionScriptDefault_Text">getOperation</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptString">&apos;getBookInfo&apos;</span><span class="ActionScriptBracket/Brace">)</span>.<span class="ActionScriptDefault_Text">send</span><span class="ActionScriptBracket/Brace">(</span> <span class="ActionScriptDefault_Text">userId</span> <span class="ActionScriptBracket/Brace">)</span>;
    <span class="ActionScriptDefault_Text">backToUnsub</span><span class="ActionScriptBracket/Brace">()</span>;
<span class="ActionScriptBracket/Brace">}</span>

<span class="ActionScriptComment">//获取用户已定航班信息
</span><span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">getBookInfoHandler</span><span class="ActionScriptBracket/Brace">(</span> <span class="ActionScriptDefault_Text">evt</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">ResultEvent</span> <span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
<span class="ActionScriptBracket/Brace">{</span>
    <span class="ActionScriptComment">//响应获取航班事件，并修改控件
</span>    <span class="ActionScriptDefault_Text">bookList</span>.<span class="ActionScriptDefault_Text">dataProvider</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">evt</span>.<span class="ActionScriptDefault_Text">result</span>;
<span class="ActionScriptBracket/Brace">}</span>

<span class="ActionScriptComment">//要退票的航班ID
</span><span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">unSubId</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">String</span>;

<span class="ActionScriptComment">//触发列表单击事件
</span><span class="ActionScriptComment">//提交要获取的座位信息的航班号
</span><span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">getDetail</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">event</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Event</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
<span class="ActionScriptBracket/Brace">{</span>
    <span class="ActionScriptDefault_Text">unSubId</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bookList</span>.<span class="ActionScriptDefault_Text">selectedItem</span>.<span class="ActionScriptDefault_Text">id</span>;
    <span class="ActionScriptDefault_Text">unSubId</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">unSubId</span>.<span class="ActionScriptDefault_Text">toString</span><span class="ActionScriptBracket/Brace">()</span>;
    <span class="ActionScriptDefault_Text">FlightService</span>.<span class="ActionScriptDefault_Text">getOperation</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptString">&apos;getSeatInfo&apos;</span><span class="ActionScriptBracket/Brace">)</span>.<span class="ActionScriptDefault_Text">send</span><span class="ActionScriptBracket/Brace">(</span> <span class="ActionScriptDefault_Text">bookList</span>.<span class="ActionScriptDefault_Text">selectedItem</span>.<span class="ActionScriptDefault_Text">id</span> <span class="ActionScriptBracket/Brace">)</span>;
<span class="ActionScriptBracket/Brace">}</span>

<span class="ActionScriptComment">//获取服务器返回的座位列表
</span><span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">getSeatInfoHandler</span><span class="ActionScriptBracket/Brace">(</span> <span class="ActionScriptDefault_Text">evt</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">ResultEvent</span> <span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
<span class="ActionScriptBracket/Brace">{</span>
    <span class="ActionScriptDefault_Text">currentState</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;seatList&quot;</span>;
    <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">bookedSeat</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Array</span><span class="ActionScriptBracket/Brace">()</span>;
    <span class="ActionScriptDefault_Text">bookedSeat</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">evt</span>.<span class="ActionScriptDefault_Text">result</span> <span class="ActionScriptReserved">as</span> <span class="ActionScriptDefault_Text">Array</span>;
    <span class="ActionScriptDefault_Text">bookSeatList</span>.<span class="ActionScriptDefault_Text">dataProvider</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bookedSeat</span>;
<span class="ActionScriptBracket/Brace">}</span>

<span class="ActionScriptComment">//提交退票信息到服务器
</span><span class="ActionScriptComment">//退订指定座位
</span><span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">unsubTickets</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
<span class="ActionScriptBracket/Brace">{</span>
    <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">seat</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bookSeatList</span>.<span class="ActionScriptDefault_Text">selectedItems</span>;
    <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">ix</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span> <span class="ActionScriptOperator">=</span> 0;
    <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">seatStr</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">String</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">null</span>;
    <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">quantity</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">seat</span>.<span class="ActionScriptDefault_Text">length</span>;
    <span class="ActionScriptReserved">for</span><span class="ActionScriptBracket/Brace">(</span> <span class="ActionScriptDefault_Text">ix</span> <span class="ActionScriptOperator">=</span> 0 ; <span class="ActionScriptDefault_Text">ix</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">quantity</span>; <span class="ActionScriptDefault_Text">ix</span><span class="ActionScriptOperator">++</span> <span class="ActionScriptBracket/Brace">)</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptReserved">if</span><span class="ActionScriptBracket/Brace">(</span> <span class="ActionScriptDefault_Text">seatStr</span> <span class="ActionScriptOperator">==</span> <span class="ActionScriptReserved">null</span> <span class="ActionScriptBracket/Brace">)</span>
            <span class="ActionScriptDefault_Text">seatStr</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">seat</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">ix</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptString">&apos;label&apos;</span><span class="ActionScriptBracket/Brace">]</span>;
        <span class="ActionScriptReserved">else</span>
            <span class="ActionScriptDefault_Text">seatStr</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">seatStr</span> <span class="ActionScriptOperator">+</span> <span class="ActionScriptString">&quot;,&quot;</span> <span class="ActionScriptOperator">+</span> <span class="ActionScriptDefault_Text">seat</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">ix</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptString">&apos;label&apos;</span><span class="ActionScriptBracket/Brace">]</span>;    
    <span class="ActionScriptBracket/Brace">}</span>
    <span class="ActionScriptDefault_Text">FlightService</span>.<span class="ActionScriptDefault_Text">getOperation</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptString">&apos;unsubTickets&apos;</span><span class="ActionScriptBracket/Brace">)</span>.<span class="ActionScriptDefault_Text">send</span><span class="ActionScriptBracket/Brace">(</span> <span class="ActionScriptDefault_Text">unSubId</span>, <span class="ActionScriptDefault_Text">seatStr</span>, <span class="ActionScriptDefault_Text">quantity</span> <span class="ActionScriptBracket/Brace">)</span>;
<span class="ActionScriptBracket/Brace">}</span>

<span class="ActionScriptComment">//退订全部座位
</span><span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">unsubAllTickets</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
<span class="ActionScriptBracket/Brace">{</span>
    <span class="ActionScriptDefault_Text">FlightService</span>.<span class="ActionScriptDefault_Text">getOperation</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptString">&apos;unsubTickets&apos;</span><span class="ActionScriptBracket/Brace">)</span>.<span class="ActionScriptDefault_Text">send</span><span class="ActionScriptBracket/Brace">(</span> <span class="ActionScriptDefault_Text">unSubId</span> <span class="ActionScriptBracket/Brace">)</span>;
<span class="ActionScriptBracket/Brace">}</span>

<span class="ActionScriptComment">//处理提交之后服务器返回的信息
</span><span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">unsubTicketsHandler</span><span class="ActionScriptBracket/Brace">(</span> <span class="ActionScriptDefault_Text">evt</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">ResultEvent</span> <span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
<span class="ActionScriptBracket/Brace">{</span>
    <span class="ActionScriptDefault_Text">CursorManager</span>.<span class="ActionScriptDefault_Text">removeBusyCursor</span><span class="ActionScriptBracket/Brace">()</span>;
    <span class="ActionScriptReserved">if</span><span class="ActionScriptBracket/Brace">(</span> <span class="ActionScriptDefault_Text">evt</span>.<span class="ActionScriptDefault_Text">result</span> <span class="ActionScriptBracket/Brace">)</span>
        <span class="ActionScriptDefault_Text">Alert</span>.<span class="ActionScriptDefault_Text">show</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptString">&apos;退票成功,点击确定跳转到主页面&apos;</span>,<span class="ActionScriptString">&apos;订票成功&apos;</span>,<span class="ActionScriptDefault_Text">Alert</span>.<span class="ActionScriptDefault_Text">YES</span>,<span class="ActionScriptReserved">this</span>,<span class="ActionScriptDefault_Text">alertHandler</span>,<span class="ActionScriptReserved">null</span>,<span class="ActionScriptDefault_Text">Alert</span>.<span class="ActionScriptDefault_Text">YES</span><span class="ActionScriptBracket/Brace">)</span>;
    <span class="ActionScriptReserved">else</span>
        <span class="ActionScriptDefault_Text">Alert</span>.<span class="ActionScriptDefault_Text">show</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptString">&apos;退票失败，请重新选择，或者检查网络是否连通&apos;</span><span class="ActionScriptBracket/Brace">)</span>;
<span class="ActionScriptBracket/Brace">}</span></pre></body>
</html>
